file(GLOB_RECURSE X_TOOLS_COMMOM_SOURCE_H "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
file(GLOB_RECURSE X_TOOLS_COMMOM_SOURCE_UI "${CMAKE_CURRENT_SOURCE_DIR}/*.ui")
file(GLOB_RECURSE X_TOOLS_COMMOM_SOURCE_CPP "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")

set(ALL_SOURCE "")
list(APPEND ALL_SOURCE ${X_TOOLS_COMMOM_SOURCE_H})
list(APPEND ALL_SOURCE ${X_TOOLS_COMMOM_SOURCE_UI})
list(APPEND ALL_SOURCE ${X_TOOLS_COMMOM_SOURCE_CPP})
list(APPEND ALL_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/xToolsCommon.qrc)

if(NOT X_TOOLS_ENABLE_MODULE_BLUETOOTH)
  message(STATUS "Bluetooth module is disable, bluetooth files will be removed.")
  set(TMP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/Common/xToolsBleScanner.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/Common/xToolsBleScanner.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsBleDeviceInfoComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsBleDeviceInfoComboBox.cpp)
endif()

if(NOT X_TOOLS_ENABLE_MODULE_SERIALPORT)
  message(STATUS "SerialPort module is disable, serial port files will be removed.")
  set(TMP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/Common/xToolsSerialPortScanner.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/Common/xToolsSerialPortScanner.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsBaudRateComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsBaudRateComboBox.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsDataBitsComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsDataBitsComboBox.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsFlowControlComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsFlowControlComboBox.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsParityComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsParityComboBox.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsPortNameComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsPortNameComboBox.cpp)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsStopBitsComboBox.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsStopBitsComboBox.cpp)
endif()

if(NOT X_TOOLS_ENABLE_MODULE_STYLESHEET)
  message(STATUS "Stylesheet module is disable, stylesheet files will be removed.")
  set(TMP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsStyleSheetManager.h)
  list(REMOVE_ITEM ALL_SOURCE ${TMP_DIR}/CommonUI/xToolsStyleSheetManager.cpp)
endif()

add_library(xToolsCommon STATIC ${ALL_SOURCE})
x_tools_add_stylesheet_files(xToolsCommon)
x_tools_generate_translations(xToolsCommon)

target_link_libraries(xToolsCommon PUBLIC glog::glog)
target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::Gui)
target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::Svg)
target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::Core)
target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::Network)

if(X_TOOLS_ENABLE_MODULE_SERIALBUS)
  target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::SerialBus)
endif()
if(X_TOOLS_ENABLE_MODULE_SERIALPORT)
  target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::SerialPort)
endif()
if(X_TOOLS_ENABLE_MODULE_BLUETOOTH)
  target_link_libraries(xToolsCommon PUBLIC Qt${QT_VERSION_MAJOR}::Bluetooth)
endif()
